<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>项目阶段设置</title>
    <link rel="stylesheet" href="${re.contextPath}/plugin/layui/css/layui.css" media="all"/>
    <!--公用样式-->
    <link rel="stylesheet" href="${re.contextPath}/plugin/common/css/comment.css">
    <!--页面样式-->
    <link rel="stylesheet" href="${re.contextPath}/plugin/common/css/style.css">
    <link rel="stylesheet" href="${re.contextPath}/plugin/common/css/extended.css">
    <script type="text/javascript" src="${re.contextPath}/plugin/layui/layui.all.js"></script>
    <script type="text/javascript" src="${re.contextPath}/plugin/jquery/jquery-3.2.1.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="${re.contextPath}/plugin/common/js/comment.js"></script>
</head>
<body class="whitebg">
<div class="myDataCentere mydataCentere-small addformstage" style="height: 500px!important;">
    <form id="myForm" class="layui-form">

        <#if "${type}"=="1">
        <div class="layui-inline">
            <label>
                <span class="red">*</span>阶段名称
            </label>
            <div >
                <input type="text" id="stageName" name="stageName"  placeholder="请填写阶段名称" style="width: 500px !important;"  autocomplete="off" lay-verify="stageName"  >
            </div>
        </div>
        </#if>
        <#if "${type}"=="2">
            <div class="layui-inline">
                <label>
                    <span class="red">*</span>阶段名称
                </label>
                <div >
                    <input type="text" id="parentStageName" name="parentStageName"  placeholder="请填写阶段名称"  disabled value="${parentStage.stageName}"  style="width: 500px !important;"  autocomplete="off"   >
                </div>
            </div>
        <div class="layui-inline">
            <label>
                <span class="red">*</span>子阶段名称
            </label>
            <div >
                <input type="text" id="stageName" name="stageName"  placeholder="请填写子阶段名称" style="width: 500px !important;"  autocomplete="off" lay-verify="stageName"  >
            </div>

        </div>
        </#if>

        <div class="layui-inline">
            <label >
                <span class="red">*</span>开始时间
            </label>
            <div class="layui-input-inline">
                <input type="text" id="startDate" name="startDate"  placeholder="请填写开始时间"  style="width: 500px !important;"   autocomplete="off" lay-verify="startDate"  class="layui-input">
            </div>
        </div>

        <div class="layui-inline">
            <label >
                <span class="red">*</span>结束时间
            </label>
            <div class="layui-input-inline">
                <input type="text" id="endDate" name="endDate"  placeholder="请填写结束时间"    style="width: 500px !important;"   autocomplete="off" lay-verify="endDate"   class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label >
                <span class="red">*</span>序号
            </label>
            <div class="layui-input-inline">
                <input type="number" id="orderNum" name="orderNum"   style="width: 500px !important;" placeholder="请填写序号"  autocomplete="off" lay-verify="orderNum"   class="layui-input">
            </div>
        </div>
        <div class="layui-form-item" style=" float: right;margin-right: 30px;margin-top: 8px">

            <button  class="layui-btn layui-btn-primary" id="close">
                关闭
            </button>
            <button  class="layui-btn layui-btn-normal" lay-filter="add" lay-submit="">
                保存
            </button>

        </div>
    </form>
</div>


<script type="text/javascript" src="${re.contextPath}/plugin/tools/tool.js"></script>
<script>
    var fbId = "${fbId}";
    var projectId = "${projectId}";
    var parentId = "${parentId}";

    layui.use(['form','layer','laydate'], function(){
        $ = layui.jquery;
        var form = layui.form
            ,layer = layui.layer, laydate = layui.laydate;

        $('#close').click(function(){
            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
        });

        laydate.render({
            elem: '#startDate'
            ,format: 'yyyy-MM-dd',
            trigger: 'click'
        });
        laydate.render({
            elem: '#endDate',
            format: 'yyyy-MM-dd',
            trigger: 'click'
        });
        // 自定义验证规则
        form.verify({
            orderNum: function(value) {
                if (value.trim() == "") {
                    return '序号不能为空';
                }
                if (!/^\d+$/.test(value)) {
                    return '只能输入数字';
                }
            },
            startDate: function(value) {
                if (value.trim() == "") {
                    return '开始时间不能为空';
                }
                if($('#endDate').val()){
                    if (value > $('#endDate').val()) {
                        return '开始时间不能大于结束时间';
                    }
                }

            },
            endDate: function(value) {
                if (value.trim() == "") {
                    return '结束时间不能为空';
                }
                if($('#startDate').val()){
                    if (value < $('#startDate').val()) {
                        return '结束时间不能小于开始时间';
                    }
                }

            },
            stageName: function(value) {
                if (value.trim() == "") {
                    return '阶段名称不能为空';
                }
            }
        })
        form.on('submit(add)', function(data){
            var stageName = $('#stageName').val();
            var orderNum = $('#orderNum').val();
            var startDate = $('#startDate').val();
            var endDate = $('#endDate').val();
            console.log(stageName,"阶段名称")
            console.log(orderNum,"序号")
            console.log(startDate,"开始时间")
            console.log(endDate,"结束时间")
            console.log(layer,"结束时间")
            var json = {
                stageName: stageName,
                orderNum: orderNum,
                startDateStr: startDate,
                endDateStr: endDate,
                parentId:parentId,
                fbId:fbId,
                projectId:projectId,
            }
            layerAjax('/project/projectManager/projectJd/addJdStage',json, '',
                function (d) {
                    console.log(d);
                    if (d.flag == true) {
                        parent.layer.msg(d.msg, {icon: 1});
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                    } else {
                        layer.msg(d.msg, {icon: 2});
                    }
                });
            return false;
        });
    });
</script>
</body>

<style>
    .addformstage{
        margin-left: 100px;
        height: 100%;
        background-color: white;


    }
    </style>





</html>
